<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<jsp:include page="common/header.jsp">
    <jsp:param name="title" value="搜索结果 - 天天新闻网"/>
</jsp:include>

<main class="container mt-4">
    <div class="search-results">
        <!-- 搜索结果头部 -->
        <div class="search-header mb-4">
            <h4>搜索结果：${keyword}</h4>
            <p class="text-muted">共找到 ${resultCount} 条相关新闻</p>
        </div>

        <!-- 搜索结果列表 -->
        <div class="news-list">
            <c:if test="${empty searchResults}">
                <div class="no-results text-center py-5">
                    <i class="fas fa-search fa-3x text-muted mb-3"></i>
                    <h5>未找到相关新闻</h5>
                    <p class="text-muted">请尝试使用其他关键词搜索</p>
                </div>
            </c:if>
            
            <c:forEach items="${searchResults}" var="news">
                <div class="news-item">
                    <div class="row">
                        <div class="col-md-3">
                            <div class="news-img">
                                <img src="images/${empty news.img_url ? 'default.png' : news.img_url}" 
                                     alt="" class="img-fluid rounded">
                            </div>
                        </div>
                        <div class="col-md-9 d-flex flex-column">
                            <div class="news-content flex-grow-1">
                                <h5 class="news-title">
                                    <a href="newsDetail?id=${news.new_id}" class="text-decoration-none text-dark">
                                        ${news.title}
                                    </a>
                                </h5>
                                <p class="news-excerpt text-muted mb-3" style="width: 52rem;text-indent: 1.5rem;">
                                    ${fn:substring(news.content, 0, 200)}...
                                </p>
                            </div>
                            <div class="news-meta text-muted mt-auto" style="width: 52rem;">
                                <span class="me-3"><i class="fas fa-user me-1"></i>${news.writer}</span>
                                <span><i class="fas fa-clock me-1"></i>${news.newTime}</span>
                            </div>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>
</main>

<jsp:include page="common/footer.jsp"/> 